home *** CD-ROM | disk | FTP | other *** search
- Path: hubcap.clemson.edu!hubcap!mjs
- From: mjs@hubcap.clemson.edu (M. J. Saltzman)
- Newsgroups: comp.lang.c
- Subject: Re: operator % - compiler error
- Date: 17 Mar 96 21:36:19 GMT
- Organization: Clemson University
- Message-ID: <mjs.827098579@hubcap>
- References: <4ihuuh$6ul@hatathli.csulb.edu>
- NNTP-Posting-Host: hubcap.clemson.edu
- X-Newsreader: NN version 6.5.0 #1
-
- davidcho@csulb.edu (David Cho) writes:
-
- >When I try to compile, I get an erro message for the following line:
-
- >x=663608941*y%pow(2,32) /*I want remainder*/
-
- >But the error message says "illegal use of floating point". What does
- >that mean? Isn't % used a an operator to calcuate the remainder?
-
- Both operands of % must be integral types, but pow() returns a double
- (assuming you've #included <math.h>). You didn't tell us if y is an
- int or not.
-
- You have a couple of options:
-
- (1) Do the entire compilation in doubles and use fmod() instead of %.
- Calculations involving exclusively integer operands should be done
- exactly if all intermediate results fit in the mantissa of a double
- (56 bits for IEEE doubles, I think).
-
- (2) Find a way to construct 2 to the 32nd power (damn, it would be
- nice to have an acceptable C syntax for that--one always gets abuse in
- comp.lang.c for the common notations 2^32 or 2**32) in an integral
- type. You could do this (with bit shifts repeated squares) if your
- architecture has 64-bit longs, but it's not portable.
-
- (3) Rethink how you are doing this computation. In 32-bit integers,
- you run the risk of overflow while computing the product anyway (if y
- is an int).
- --
- Matthew Saltzman
- Clemson University Math Sciences
- mjs@clemson.edu
-